package calculator_
//package main
import (
	"fmt"
	"os"
	"strconv"
)

func main() {
	// 定长数组的使用
	nums := [10]int{1, 3, 5, 6}
	for i := 0; i < len(nums); i++ {
		fmt.Printf("The num is: %d \n", i)
	}

	for k, v := range nums {
		// v 是一个临时变量
		v += 2
		fmt.Println("key is :", k, "value is :", v, "the nums[", k, "]", ":", nums[k])
	}
	nums2 := nums[0:3]
	fmt.Println("nums2: ", nums2)
	nums2[2] = 999
	fmt.Println("nums2: ", nums2, "nums: ", nums)

	// make
	new_nums := make([]string, 10, 20)
	new_nums[0] = "hello"
	new_nums[1] = "world"
	fmt.Println("new_nums is: ", new_nums)
	//copy
	nums3 := copy(nums2, nums2[0:3])
	fmt.Println("nums3:", nums3)

	// map
	new_map := make(map[int]string, 20)
	new_map[0] = "hello"
	new_map[1] = "world"
	for key, value := range new_map {
		fmt.Println("the key is: ", key, "the value is :", value)
	}
	value, ok := new_map[0]
	if ok {
		fmt.Println("the value is:", value)
	} else {
		fmt.Println("the value is not exist：", value)
	}

	delete(new_map, 1)
	fmt.Println("now new_map is :", new_map)
	delete(new_map, 100) // 不会报错
	fmt.Println("now new_map is :", new_map)

	number1, _ := strconv.Atoi(os.Args[1])
	number2, _ := strconv.Atoi(os.Args[2])
	res := number_add(number1, number2)
	println("result:", res)

	// 函数
	s := "test-str"
	change_val(&s)
	fmt.Println("value is :", s)
}

func number_add(num1 int, num2 int) int {
	return num1 + num2
}

func change_val(val *string){
	// 系统不会发送值，而是发送变量的内存地址
	*val = "hello-kitty"
}